package com.heima.schedule.feign;

import com.heima.apis.article.schedule.IscheduleClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.dtos.Task;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiaoxiaode
 * @date 2021/10/5 20:23
 **/
@RestController
public class scheduleClient implements IscheduleClient {


    @Autowired
    private TaskService taskService;


    /*
    * 添加延时任务
    *
    * */
    @PostMapping("/api/v1/task/add")
    public ResponseResult addTask(@RequestBody Task task){
        return ResponseResult.okResult(taskService.addTask(task));
    };


    /*
     *
     * 取消任务
     * */
    @GetMapping("/api/v1/task/{taskId}")
    public ResponseResult canceTask(@PathVariable("taskId") long taskId){
        return ResponseResult.okResult(taskService.canceTask(taskId));
    };


    /*
     *
     * 按照类型和优先级拉取任务
     * */
    @GetMapping("/api/v1/task/{type}/{priority}")
    public ResponseResult poll(@PathVariable("type")int type, @PathVariable("priority")int priority){
        return ResponseResult.okResult(taskService.poll(type,priority));
    };
}
